package com.bite.principal.controller;

import com.bite.principal.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DogController {
    @Autowired
    private ApplicationContext context;

    @Autowired
    private Dog singleDog;

    @Autowired
    private Dog prototypeDog;

    @Autowired
    private Dog requestDog;

    @Autowired
    private Dog sessionDog;

    @Autowired
    private Dog applicationDog;

    @RequestMapping("single")
    public String single() {
        Dog contextDog = context.getBean("singleDog", Dog.class);
        return "content: " + contextDog + ", autowired 注解: " + singleDog;
    }

    @RequestMapping("prototype")
    public String prototype() {
        Dog contextDog = context.getBean("prototypeDog", Dog.class);
        return "content: " + contextDog + ", autowired 注解: " + prototypeDog;
    }

    @RequestMapping("request")
    public String request() {
        Dog contextDog = context.getBean("requestDog", Dog.class);
        return "content: " + contextDog + ", autowired 注解: " + requestDog;
    }

    @RequestMapping("application")
    public String application() {
        Dog contextDog = context.getBean("applicationDog", Dog.class);
        return "content: " + contextDog + ", autowired 注解: " + applicationDog;
    }

    @RequestMapping("session")
    public String session() {
        Dog contextDog = context.getBean("sessionDog", Dog.class);
        return "content: " + contextDog + ", autowired 注解: " + sessionDog;
    }

}
